﻿using ModuleBase;
using System.Diagnostics;

namespace EndModel
{
    public class EndModel : ModuleBase.ModuleBase
    {
        private ModuleStateService _moduleStateService;
        bool outputs = false;

        public EndModel(ModuleStateService moduleStateService)
        {
            _moduleStateService = moduleStateService;
            _moduleStateService.RegisterModule(Id);
            Name = "End";
        }

        public override bool Execute(ModuleBase.ExecutionContext context)
        {

            if (_moduleStateService.IsStopped)
            {
                outputs["Input1"] = false;
            }
            if (_moduleStateService.GetModuleExecutionStatus(Id))
            {
                outputs["Input1"] = true;
            }
            _moduleStateService.SetModuleExecutionStatus(Id, true);
            return outputs;
        }

        public override async Task<bool> ExecuteAsync(ModuleBase.ExecutionContext context)
        {
            var result = await Task.Run(() => Execute(context));
            return result;
        }

        public override void Initialize()
        {

        }
    }
}
